package ibm.abacus.concurrency;

public class SynchronizedTest {

	static Object lock = new Object();

	static class LocalThread extends Thread {
		public void run() {
			print();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		LocalThread[] threads = new LocalThread[3];
		for (int i = 0; i < threads.length; i++) {
			threads[i] = new LocalThread();
			System.out.println("New:" + threads[i].getName());
			threads[i].start();
		}

	}

	public synchronized static void print() {
		System.out.println("Enter: " + Thread.currentThread().getName());
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("Left: " + Thread.currentThread().getName());
		/*
		 * 
		 * synchronized (lock) {
		 * System.out.println(Thread.currentThread().getName()); try {
		 * lock.wait(1000);
		 * System.out.println(Thread.currentThread().getName()); } catch
		 * (InterruptedException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); } lock.notifyAll(); }
		 */
	}

}
